home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / nivb / selfile.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-05-07  |  9.8 KB  |  284 lines

  1. VERSION 2.00
  2. Begin Form SelectFileForm 
  3.    BorderStyle     =   3  'Fixed Double
  4.    Caption         =   "Select File"
  5.    ClientHeight    =   3735
  6.    ClientLeft      =   1935
  7.    ClientTop       =   1665
  8.    ClientWidth     =   5700
  9.    ControlBox      =   0   'False
  10.    FontBold        =   -1  'True
  11.    FontItalic      =   0   'False
  12.    FontName        =   "System"
  13.    FontSize        =   9.75
  14.    FontStrikethru  =   0   'False
  15.    FontUnderline   =   0   'False
  16.    Height          =   4140
  17.    Icon            =   0
  18.    Left            =   1875
  19.    LinkMode        =   1  'Source
  20.    LinkTopic       =   "Form1"
  21.    MaxButton       =   0   'False
  22.    MinButton       =   0   'False
  23.    ScaleHeight     =   3735
  24.    ScaleWidth      =   5700
  25.    Top             =   1320
  26.    Width           =   5820
  27.    Begin DriveListBox DriveBox 
  28.       Height          =   315
  29.       Left            =   2895
  30.       TabIndex        =   7
  31.       Top             =   3135
  32.       Width           =   2475
  33.    End
  34.    Begin CommandButton CancelButton 
  35.       Cancel          =   -1  'True
  36.       Caption         =   "&Cancel"
  37.       Height          =   420
  38.       Left            =   1560
  39.       TabIndex        =   9
  40.       Top             =   3120
  41.       Width           =   1125
  42.    End
  43.    Begin CommandButton OKButton 
  44.       Caption         =   "&OK"
  45.       Default         =   -1  'True
  46.       Height          =   420
  47.       Left            =   240
  48.       TabIndex        =   8
  49.       Top             =   3120
  50.       Width           =   1125
  51.    End
  52.    Begin DirListBox DirBox 
  53.       Height          =   1880
  54.       Left            =   2910
  55.       TabIndex        =   5
  56.       Top             =   880
  57.       Width           =   2460
  58.    End
  59.    Begin FileListBox FileListBox 
  60.       Height          =   1785
  61.       Left            =   240
  62.       TabIndex        =   2
  63.       Top             =   840
  64.       Width           =   2460
  65.    End
  66.    Begin TextBox FileNameBox 
  67.       Height          =   320
  68.       Left            =   195
  69.       TabIndex        =   1
  70.       Text            =   "*.*"
  71.       Top             =   400
  72.       Width           =   2610
  73.    End
  74.    Begin Label Label3 
  75.       Caption         =   "Dri&ves:"
  76.       Height          =   255
  77.       Left            =   2835
  78.       TabIndex        =   6
  79.       Top             =   2850
  80.       Width           =   765
  81.    End
  82.    Begin Label CurrDirLabel 
  83.       Caption         =   "---"
  84.       Height          =   225
  85.       Left            =   2880
  86.       TabIndex        =   4
  87.       Top             =   480
  88.       Width           =   2445
  89.    End
  90.    Begin Label Label2 
  91.       Caption         =   "&Directories:"
  92.       Height          =   240
  93.       Left            =   2820
  94.       TabIndex        =   3
  95.       Top             =   150
  96.       Width           =   1200
  97.    End
  98.    Begin Label Label1 
  99.       Caption         =   "File &Name:"
  100.       Height          =   240
  101.       Left            =   120
  102.       TabIndex        =   0
  103.       Top             =   120
  104.       Width           =   1200
  105.    End
  106. Dim LastChange As Integer   'remember what changed last
  107. Sub CancelButton_Click ()
  108.     Unload SelectFileForm
  109. End Sub
  110. Sub DirBox_Change ()
  111.     ' propogate directory changes to other controls
  112.     FileListBox.Path = DirBox.Path
  113.     CurrDirLabel.Caption = DirBox.Path
  114.     ChDir DirBox.Path
  115. End Sub
  116. Sub DirBox_Click ()
  117.     LastChange = 2  'remember that the DirBox control changed
  118. End Sub
  119. Sub DriveBox_Change ()
  120.     ' change the DirBox control path, it will
  121.     ' pass the change on to the FileListBox control
  122.     DirBox.Path = DriveBox.Drive
  123.     ChDrive (DriveBox.Drive)
  124. End Sub
  125. Sub FileListBox_Click ()
  126.     'echo the selected name in the Text box
  127.     FileNameBox.Text = FileListBox.FileName
  128. End Sub
  129. Sub FileListBox_DblClick ()
  130.     'we have a final selection from the File Save dialog
  131.     FileNameBox.Text = FileListBox.FileName
  132.     OKButton_Click
  133. End Sub
  134. Sub FileListBox_PathChange ()
  135.     'Show the current search pattern in the FileNameBox control
  136.     FileNameBox.Text = FileListBox.Pattern
  137.     HighLightTextBox
  138. End Sub
  139. Sub FileListBox_PatternChange ()
  140.     FileNameBox.Text = FileListBox.Pattern
  141.     HighLightTextBox
  142. End Sub
  143. Sub FileNameBox_Change ()
  144.     LastChange = 1
  145. End Sub
  146. Sub Form_Load ()
  147.     If (currentForm = AFP_FORM) Then
  148.         Unload AFPForm
  149.     End If
  150.     CurrDirLabel.Caption = DirBox.Path  'Show full path name in a label
  151.     LastChange = 0                          'No controls have been modified
  152.     DirBox.Height = FileListBox.Height      'Align Drives box to Files box
  153. End Sub
  154. Sub HighLightTextBox ()
  155.     FileNameBox.SelStart = 0
  156.     FileNameBox.SelLength = Len(FileNameBox.Text)
  157.     FileNameBox.SetFocus
  158. End Sub
  159. Function IsFileName (FileSpec As String) As Integer
  160. ' This function accepts FileSpec, a string, as input, then
  161. ' checks to see if the string is a valid file path/expression.
  162. ' If FileSpec is valid, and specifies a new drive, pattern and/or
  163. ' directory, the directory and file list boxes are notified.
  164. ' If FileSpec contains a valid file name, the filename is placed
  165. ' in the form's text edit box and IsFileName() returns a value of
  166. ' TRUE.  If FileSpec does not contain a valid file name (ie, it
  167. ' contains directory name and/or a new file pattern and/or an
  168. ' invalid file/path expression), IsFileName() returns FALSE.
  169.     Dim Index As Integer
  170.     Dim OldDir As String
  171.     Dim NewDir As String
  172.     On Local Error Resume Next
  173.     OldDir = CurDir$                    'Remember current directory
  174.     FileSpec = LCase$(FileSpec)
  175.     If Mid$(FileSpec, 2, 1) = ":" Then  'Does it specify new drive?
  176.         ChDrive (FileSpec)
  177.         DirBox.Path = CurDir$
  178.         If Err Then
  179.             MsgBox Error$(Err), 0, "Disk Error"
  180.             ChDrive (OldDir)
  181.             DirBox.Path = CurDir$
  182.             IsFileName = False
  183.             Exit Function
  184.         Else FileSpec = Right$(FileSpec, Len(FileSpec) - 2)
  185.         End If
  186.     End If
  187.     ChDir (FileSpec)
  188.     If Err Then                     'Separate path/filename, try again
  189.         While InStr(FileSpec, "\")      'Parse any directory info
  190.         
  191.             'NewDir gets text to the left of & including FileSpec's first "\"
  192.             NewDir = NewDir + Left$(FileSpec, InStr(FileSpec, "\"))
  193.         
  194.             'FileSpec becomes the text to the right of the first "\"
  195.             FileSpec = Right$(FileSpec, Len(FileSpec) - InStr(FileSpec, "\"))
  196.         Wend
  197.         
  198.         If NewDir <> "" Then
  199.             If Len(NewDir) > 1 Then NewDir = Left$(NewDir, Len(NewDir) - 1)'Remove ending "\"
  200.             Err = 0
  201.             ChDir (NewDir)
  202.             If Err Then
  203.                 MsgBox "Invalid path: '" + NewDir + "'", 0, "Cardfile"
  204.                 IsFileName = False
  205.             Else
  206.                 If ProcessFileSpec(FileSpec) Then
  207.                     IsFileName = True
  208.                 Else
  209.                     If (InStr(FileSpec, "*") = 0) And (InStr(FileSpec, "?") = 0) Then
  210.                         ChDrive (OldDir)
  211.                         ChDir (OldDir)
  212.                     Else
  213.                         DirBox.Path = CurDir$     'Update file controls
  214.                     End If
  215.                     IsFileName = False
  216.                 End If
  217.             End If
  218.         Else
  219.             IsFileName = ProcessFileSpec(FileSpec)
  220.         End If
  221.     Else
  222.         'User specified a new, valid dir; update the file controls
  223.         DirBox.Path = FileSpec
  224.     End If
  225. End Function
  226. Sub OKButton_Click ()
  227.     Dim FileSpec As String
  228.     Select Case LastChange
  229.         Case 0 To 1             'Text box control was last changed
  230.             LastChange = False
  231.             FileSpec = FileNameBox.Text
  232.             If IsFileName(FileSpec) Then
  233.                 HighLightTextBox
  234.                 SelectFileForm.Hide
  235.                 If (currentForm = AFP_FORM) Then
  236.                     AFPInfoForm.Show
  237.                 Else
  238.                     FileInfoForm.Show
  239.                 End If
  240.             End If
  241.         Case 2               'Directory list control was last changed
  242.             LastChange = False
  243.             DirBox.Path = DirBox.List(DirBox.ListIndex)
  244.         End Select
  245. End Sub
  246. Function ProcessFileSpec (FileSpec As String) As Integer
  247. ' This function accepts a string which may be a directory name,
  248. ' a wildcard pattern, or a file name.  The function returns TRUE
  249. ' if the string is a valid filename, and FALSE if the string is
  250. ' either an invalid filename or a directory specification.  If the
  251. ' string specifies a directory, ProcessFileSpec() changes the
  252. ' current directory and updates the appropriate form controls.
  253.     Dim MsgBoxResponse As Integer
  254.     On Local Error Resume Next
  255.     If FileSpec <> "" Then
  256.         Err = 0
  257.         ChDir (FileSpec)
  258.         If Err Then     ' FileSpec is a filename or wildcard, not a dir
  259.             'If InStr(FileSpec, ".") = False Then FileSpec = FileSpec + ".crd"
  260.             If Len(FileSpec) > 12 Then
  261.                 MsgBox ("Filename too long: '" + FileSpec + "'")
  262.                 ProcessFileSpec = False
  263.             Else
  264.                 'Did user specify a new wildcard pattern?
  265.                 If InStr(FileSpec, "*") Or InStr(FileSpec, "?") Then
  266.                     FileListBox.Pattern = FileSpec
  267.                     ProcessFileSpec = False
  268.                 Else
  269.                     If FileSpec <> ".." Then
  270.                         ' We're finished -- got a valid filename
  271.                         FileNameBox.Text = FileSpec
  272.                         ProcessFileSpec = True
  273.                     End If
  274.                 End If
  275.             End If
  276.         Else   ' FileSpec was just a directory name
  277.             ProcessFileSpec = False
  278.         End If
  279.     Else
  280.         ' The user only specified a new drive (handled in IsFileName)
  281.         ProcessFileSpec = False
  282.     End If
  283. End Function
  284.